<script type="text/javascript">
var zNodes = {$json_nodes};
var setting = {
        view: {
            selectedMulti: false
        },
        edit: {
            enable: true,
            showRemoveBtn: false,
            showRenameBtn: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick       : do_open_layout
        },
    };

$(document).ready(function(){
	$.fn.zTree.init($("#layout-tree"), setting, zNodes);
	var zTree    = $.fn.zTree.getZTreeObj("layout-tree");
	
	zTree.expandAll(true);

    //寻找第一个内部栏目, 并调用点击事件
    //火狐兼容问题报event is not define
    if(typeof(event) != "undefined"){
    	var nodes = zTree.getNodes();
        // console.log(nodes)
        // if(nodes.length > 0 ){
        //     for(var i = 0; i < nodes.length; i++){
        //         if(nodes[i].type == 0){
        //             zTree.selectNode(nodes[i]);//选择点  
        //             zTree.setting.callback.onClick(event, "layout-tree", nodes[i]);//调用事件 
        //             break;
        //         }
        //     }
        // }
    } 
	
});
function do_open_layout(event, treeId, treeNode) {
	var zTree = $.fn.zTree.getZTreeObj(treeId);
	//点击父级可以查看
    if (treeNode.isParent) {
        var zTree = $.fn.zTree.getZTreeObj(treeId)
        
        zTree.expandNode(treeNode)
        return
    }
    //console.log(treeNode);
    //如果是内部栏目, 则跳出列表, 否则跳出编辑页
    $(event.target).bjuiajax('doLoad', {url: treeNode.url, target: "#layout_article"});
    /* if(treeNode.type == 0){
        $(event.target).bjuiajax('doLoad', {url: treeNode.url, target: "#layout_article"});
    }else{
    	$(event.target).bjuiajax('doLoad', {url: treeNode.url, target: "#layout_article"});
    } */
    
    event.preventDefault()
}
function ztree_returnjson() {
    return {$json_nodes}
}

</script>
<div class="bjui-pageContent">
    <div style="float:left; width:200px;">
        <ul id="layout-tree" class="ztree">
        </ul>
        <!-- <ul id="layout-tree" class="ztree" data-toggle="ztree" data-expand-all="true" data-on-click="do_open_layout" data-options="{nodes:'ztree_returnjson'}">
        </ul> -->
    </div>
    <div style="margin-left:210px; height:99.9%; overflow:hidden;">
        <div style="height:100%; overflow:hidden;">
            <fieldset style="height:100%;">
                <div id="layout_article" style="height:100%; overflow:hidden;">
                </div>
            </fieldset>
        </div>
    </div>
</div>